package bb.lanxing.device.sgdevcie.xpair.viewmodel

import android.app.Application
import bb.lanxing.device.sgdevcie.xpair.net.XPairRepository
import bb.lanxing.device.sgdevcie.xpair.uimodel.BleDescriptionDevice
import bb.lanxing.device.sgdevcie.xpair.uimodel.XPairDeviceBoundParam
import bb.lanxing.device.sgdevcie.xpair.uimodel.XPairUIModel
import bb.lanxing.mvvm.base.viewmodel.BaseViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow

class XPairViewModel(application: Application) : BaseViewModel(application) {
    val boundErrorCodeFlow: MutableSharedFlow<Pair<Int, String>> = MutableSharedFlow()
    val boundResultStateFlow: MutableStateFlow<Boolean> = MutableStateFlow(false)
    var pairTarget: BleDescriptionDevice? = null
    val xPairRepository: XPairRepository = XPairRepository.getInstance()
    var xPairUIModel: XPairUIModel? = null

    fun boundToXOSS(bleDescriptionDevice: BleDescriptionDevice) {
        execute({
            val sn = bleDescriptionDevice.sn ?: ""
            val model = bleDescriptionDevice.model ?: ""
            val manufacturer = bleDescriptionDevice.manufacturer ?: ""
            val address = bleDescriptionDevice.address ?: ""
            val name = bleDescriptionDevice.name ?: ""
            val hwVersion = bleDescriptionDevice.hwVersion ?: ""
            xPairRepository.boundDevice(
                XPairDeviceBoundParam(
                    sn,
                    model,
                    manufacturer,
                    address,
                    name,
                    hwVersion
                )
            )
        }, {

        }, {

        }, false)
    }

    public override fun onCleared() {
        super.onCleared()
    }
}
